﻿Public Class ParameterModifyClass

    ''' <summary>
    ''' 置位参数修改门变量
    ''' </summary>
    ''' <param name="netID"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Shared Function EnterModify(ByVal netID As Byte) As Boolean
        '读取当前门变量的值
        Dim b() As Short
        b = COMHelper.Instance.Send4Short(netID, FunctionCode.WordWritableRead, 7061, 1)

        If b Is Nothing Then
            'msg.Show("通讯失败,，请重试")
            Return False
        End If

        If b Is Nothing OrElse b.Length <> 1 OrElse b(0) = 3 Then
            'msg.Show("其它地方正在修改，请稍后再试")
            msg.Show("无法修改参数，请重试")
            Return False
        End If

        If b(0) = 2 Then
            Return True
        End If

        '门变量置为2
        Dim result As Boolean
        result = COMHelper.Instance.Write(netID, FunctionCode.WordWrite, 7061, 2)
        If result = False Then
            msg.ShowError("无法保存参数，请重试")
        End If

        Return result
    End Function


    ''' <summary>
    ''' 退出修改,复位参数修改门变量
    ''' </summary>
    ''' <param name="netID"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Shared Function ExitModify(ByVal netID As Byte) As Boolean
        '门变量置为1
        Dim result As Boolean
        result = COMHelper.Instance.Write(netID, FunctionCode.WordWrite, 7061, 1)
        Return result
    End Function


    ''' <summary>
    ''' 设置修改使能变量
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Shared Function SetModifyConfirm(ByVal netID As Byte) As Boolean
        Dim result As Boolean
        '参数修改使能变量；当参数备份区修改完毕后，使能确认；1=取消；2=确认；
        result = COMHelper.Instance.Write(netID, FunctionCode.WordWrite, 7062, 2)
        If result = False Then
            'msg.ShowError("修改使能变量错误。")
        End If
        Return result
    End Function

End Class
